﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBA.Data;
using DBA.Common;
using DBA.Data.ADO;
using DBA.Model;

namespace DBA.Bll
{
    public class BLLOperatingUser
    {
        /// <summary>
        /// 根据用户名和密码得到需要保存的SESSION用户信息
        /// </summary>
        /// <param name="UserName"></param>
        /// <param name="Password"></param>
        /// <returns></returns>
        public DataTable GetOperatingUser(string UserName, string Password)
        {
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            StringBuffer sql = "select A.EmployeeID,A.Name as UserName,A.SalaryID,A.Sex,A.Xi_ID,B.Name as XiName,A.Suo_ID,D.Name as SuoName,";
            sql += "A.dpt_id,C.Name as DptName,A.EaID,F.Name as EduName,A.PD_id,G.name as PartyDutyName,A.jszwzgID,E.Name as JszwzgName";
            sql += " from EmployeeInfo A left join Xi B on A.Xi_ID=B.Xi_ID left join sys_department C on A.dpt_id = C.dpt_id ";
            sql += " left join Suo D on A.Suo_ID=D.Suo_ID left join JSZWZG E on A.jszwzgID = E.jszwzgID left join EduAttainments F on A.EaID = F.EaID";
            sql += " left join PartyDuty G on A.PD_id = G.PD_id where A.Name = @UserName and Password = @Password";
            dal.ManagerParameter.ClearParameter();
            dal.ManagerParameter.AddNewInParameter("UserName", UserName);
            dal.ManagerParameter.AddNewInParameter("Password", Password);
            return dal.ExecuteFillDataTable(sql);
        }

        public DataTable GetUserRole(int employeeID)
        {
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            string sql = "select a.RoleID,b.RoleName from Sys_RoleAndUser a left join Sys_RoleInfo b on a.RoleID=b.RoleID where EmployeeID=@EmployeeID";
            dal.ManagerParameter.ClearParameter();
            dal.ManagerParameter.AddNewInParameter("EmployeeID", employeeID);
            return dal.ExecuteFillDataTable(sql);
        }

        public IList<Sys_SystemFunction> GetUserFunction(List<int> roleList)
        {
            DataAccessLibrary dal = CommonQuery.DataAccessLibrary;
            string roles = String.Join(",", roleList.ToArray());
            string sql = "select * from Sys_SystemFunction where FuncID in (select FuncID from Sys_RoleAndFunc where RoleID in (" + roles + "))";
            return dal.ModifyData.Select<Sys_SystemFunction>(sql);
        }
    }
}
